﻿using Coder.Workflow;
using Identity;

namespace Fee.Orders.PreWorkflow
{
    public class PreDelegateOrder : DelegateOrderBase
    {
        public const string WorkflowName = "预委托流程";
        public const string EditStepWorkFlowItem = "预委托单草拟";
        public const string NotifyDesigner = "设计院确认";
        public const string WorkFlowType = "PreDelegateWorkProcess";

        public PreDelegateOrder()
        {
        }

        public PreDelegateOrder(WorkProcess wrWorkProcess, User user) : base(wrWorkProcess, user)
        {
        }

        public override void Complete()
        {
            base.Complete();

            var preOrder = this;

            var task = preOrder.ConstructionTask;
            //把预委托单的内容写入 construactionTask里面。
            foreach (var delegateOrderDetail in preOrder.Details)
            {
                var taskDetail = delegateOrderDetail.FillTo(new ConstructionDetail());
                task.Details.Add(taskDetail);

                ;
                taskDetail.Status = taskDetail.ContractType == ContractType.Design
                    ? ConstructionDetailStatus.Confirm
                    : ConstructionDetailStatus.Unconfirm;

                taskDetail.Project = delegateOrderDetail.Project;
                taskDetail.ProcessInfo.Number = preOrder.Number;
                taskDetail.ProcessInfo.ConstructionOperator = delegateOrderDetail.Operator;
            }

            task.Status = ConstructionTaskStatus.PreAuthed;
        }
    }
}